/*
 * Copyright (c) 2024 ASPEED Technology Inc.
 *
 * SPDX-License-Identifier: MIT
 */

#include <zephyr/kernel.h>
#include "otp_utils.h"
#if defined(CONFIG_OTP_ASPEED) || defined(CONFIG_OTP_SIM)
#if defined(CONFIG_OTP_KEY_RETIRE)

int32_t otp_retire_key_id = 1;  // valid range : 0 - 7

// DO NOT change the below variable for key retirement.
uint8_t otp_header_slot = 0;                 // 0-based
uint8_t otp_key_id = 0;                      // 0-based
uint8_t otp_key_type = OTP_EMPTY_HEADER;
uint8_t otp_key_param = 0;
uint16_t otp_key_exp_len = 0;
uint32_t otp_key_offset = 0;               // otp data region offset for storing key
uint32_t otp_key_len = 0;
uint8_t otp_pub_key[] = { 0 };

#elif defined(CONFIG_OTP_KEY_ADD)

// Example of ECDSA384 OEM DSS key 2 :
uint8_t otp_header_slot = 2;                   // 0-based
uint8_t otp_key_id = 2;                        // 0-based
uint8_t otp_key_type = OTP_ECDSA384_PUBKEY;
uint8_t otp_key_param = OTP_KPARAM_ECDSA384;
uint16_t otp_key_exp_len = 0;
uint32_t otp_key_offset = 0x100;               // otp data region offset for storing key
uint32_t otp_key_len = 0x60;
const uint8_t otp_pub_key[] = {
	0xbb, 0xc0, 0x5b, 0xb1, 0x03, 0xac, 0xe8, 0x02,
	0x7e, 0xb9, 0x87, 0xd6, 0x5d, 0xd9, 0x0b, 0x6a,
	0x27, 0x96, 0x58, 0x83, 0xdc, 0xee, 0x13, 0xe3,
	0x67, 0x2d, 0x2b, 0x0c, 0x6f, 0x0c, 0xfa, 0x58,
	0x25, 0x71, 0x24, 0x39, 0x23, 0x18, 0x7b, 0xa3,
	0x90, 0x57, 0x2f, 0x26, 0x95, 0xd9, 0x91, 0x22,
	0x49, 0xc4, 0x0c, 0x5a, 0xd8, 0xeb, 0x1c, 0x6c,
	0x5a, 0x33, 0x7b, 0x84, 0xaf, 0xad, 0x7f, 0x0c,
	0x42, 0x46, 0xe6, 0x8b, 0x97, 0x50, 0xbb, 0xf8,
	0xbc, 0xbc, 0x11, 0x4e, 0xde, 0x69, 0x11, 0xc3,
	0x55, 0xd7, 0x15, 0x6b, 0xcb, 0xbf, 0xf5, 0xe5,
	0x1d, 0x0f, 0xa7, 0x34, 0x4e, 0xf0, 0xca, 0xe0,
};

// Example of RSA2048 OEM DSS key :
// uint8_t otp_header_slot = 2;                 // 0-based
// uint8_t otp_key_id = 2;                      // 0-based
// uint8_t otp_key_type = OTP_RSA_OEM_BE_PUBKEY;
// uint8_t otp_key_param = OTP_KPARAM_RSA2048;
// uint16_t otp_key_exp_len = 0b10001; // 65537
// uint32_t otp_key_offset = 0x440;              // otp data region offset for storing key
// uint32_t otp_key_len = 0x100;
// const uint8_t otp_pub_key[] = {
// 	0xd5, 0xcf, 0x48, 0x9d, 0x23, 0x21, 0xaf, 0x70,
// 	0xea, 0x2f, 0x14, 0xd1, 0x0f, 0x75, 0x1d, 0x57,
// 	0xbc, 0x10, 0x39, 0x03, 0x60, 0x03, 0x0e, 0x66,
// 	0x6a, 0x9e, 0x5e, 0x18, 0x43, 0xa8, 0x2d, 0x1d,
// 	0xaf, 0x1c, 0x15, 0x6a, 0xa9, 0x25, 0x3b, 0xbd,
// 	0x9e, 0x15, 0x6d, 0x40, 0x5d, 0xf6, 0x11, 0x50,
// 	0x90, 0x50, 0x8d, 0x9f, 0xcf, 0x91, 0xff, 0xdb,
// 	0x1b, 0xe8, 0xb2, 0xe6, 0xad, 0x15, 0x20, 0xd6,
// 	0x8b, 0xa4, 0x41, 0x4c, 0x5f, 0x5a, 0xe4, 0xaa,
// 	0x5b, 0x3f, 0x12, 0x2f, 0xeb, 0xab, 0xfc, 0x8f,
// 	0xb1, 0xdf, 0xc5, 0x7b, 0x91, 0x14, 0x5a, 0xff,
// 	0x0a, 0xe4, 0xb2, 0x4a, 0x41, 0x66, 0x7a, 0x9e,
// 	0xba, 0x6f, 0x93, 0x7c, 0x97, 0x47, 0x4b, 0x43,
// 	0xa6, 0xb9, 0x37, 0x6d, 0x65, 0xb0, 0x41, 0xab,
// 	0xfa, 0xa5, 0xb0, 0xac, 0x3c, 0x86, 0x70, 0x81,
// 	0x61, 0x99, 0x37, 0x3f, 0xcc, 0x90, 0x72, 0x1a,
// 	0x95, 0x49, 0xd5, 0x81, 0x00, 0x3d, 0xa0, 0x02,
// 	0xed, 0x56, 0x0a, 0x87, 0x23, 0x47, 0x0c, 0x1a,
// 	0x29, 0xdd, 0x0e, 0xc0, 0x00, 0x5e, 0x0e, 0xe9,
// 	0x7f, 0x6d, 0x44, 0xb3, 0x62, 0x79, 0x0c, 0x37,
// 	0xf3, 0x61, 0xdf, 0xbc, 0xfc, 0x6e, 0xc3, 0xf5,
// 	0xbd, 0xdb, 0x6e, 0x26, 0xa6, 0x1a, 0x1b, 0x82,
// 	0x34, 0x6c, 0x34, 0xc4, 0x9d, 0x09, 0x84, 0x0f,
// 	0x08, 0x99, 0x2e, 0x0e, 0xf2, 0xda, 0x4e, 0xd8,
// 	0x40, 0x14, 0x93, 0xef, 0xff, 0xea, 0x17, 0x68,
// 	0x02, 0xc8, 0xe7, 0xd8, 0xc9, 0xfe, 0xd6, 0x2f,
// 	0x70, 0x9a, 0x38, 0x43, 0xba, 0xa6, 0x0d, 0xf0,
// 	0x3f, 0x3e, 0xd4, 0x5d, 0x30, 0xc4, 0x96, 0x63,
// 	0x59, 0x26, 0x09, 0x5c, 0xa6, 0x09, 0x35, 0xf5,
// 	0x02, 0x9f, 0xed, 0xb2, 0xb5, 0xff, 0x8c, 0xb3,
// 	0x7d, 0xd7, 0xd4, 0x32, 0xce, 0xf2, 0x74, 0x15,
// 	0xb7, 0x20, 0xdb, 0xe7, 0xe2, 0xf4, 0xb3, 0x73,
// };

// Example of RSA3072 OEM DSS key :
// uint8_t otp_header_slot = 2;                 // 0-based
// uint8_t otp_key_id = 2;                      // 0-based
// uint8_t otp_key_type = OTP_RSA_OEM_BE_PUBKEY;
// uint8_t otp_key_param = OTP_KPARAM_RSA3072;
// uint16_t otp_key_exp_len = 0b10001; // 65537
// uint32_t otp_key_offset = 0x640;              // otp data region offset for storing key
// uint32_t otp_key_len = 0x180;
// const uint8_t otp_pub_key[] = {
// 	0xbd, 0x6f, 0x25, 0xa3, 0x24, 0xcc, 0x25, 0xf2,
// 	0xf1, 0x83, 0xe9, 0xfe, 0x2a, 0x36, 0xae, 0x14,
// 	0x86, 0x81, 0xcd, 0x88, 0x3b, 0x93, 0xf0, 0x0f,
// 	0xdd, 0x2c, 0xd9, 0x2e, 0x61, 0xe6, 0x61, 0x0b,
// 	0x36, 0x35, 0x50, 0x7d, 0x1c, 0x83, 0xbb, 0x6b,
// 	0x5b, 0x33, 0x1d, 0x20, 0x2d, 0xb4, 0x2a, 0xb4,
// 	0xf2, 0x60, 0x76, 0xbf, 0x34, 0x79, 0xb5, 0xf0,
// 	0xb2, 0x9c, 0x4d, 0x0d, 0xdb, 0xd2, 0x93, 0x1a,
// 	0x06, 0x01, 0xae, 0x8c, 0xb6, 0x16, 0xc1, 0x4d,
// 	0x68, 0xda, 0xdd, 0x58, 0xe4, 0xae, 0x12, 0x8a,
// 	0x80, 0x72, 0xba, 0x5f, 0xaa, 0x6b, 0xbf, 0xf9,
// 	0x18, 0xd8, 0xdc, 0x2e, 0x46, 0x7c, 0x1a, 0xf2,
// 	0xea, 0x80, 0xdb, 0xeb, 0x84, 0xbf, 0xad, 0x65,
// 	0x90, 0x4f, 0x45, 0x8b, 0x7b, 0x9c, 0x57, 0x37,
// 	0xf5, 0x3f, 0x27, 0x55, 0xec, 0xe3, 0x05, 0x32,
// 	0xf9, 0x83, 0x4b, 0x4f, 0x0b, 0x87, 0x41, 0xd1,
// 	0x34, 0x14, 0xbb, 0x24, 0x6a, 0x81, 0x6f, 0x70,
// 	0x42, 0xc3, 0x71, 0x90, 0x2c, 0xfd, 0xb2, 0xac,
// 	0x12, 0x4e, 0xf2, 0x91, 0xea, 0xca, 0xa0, 0x6a,
// 	0xc6, 0x11, 0x77, 0x99, 0x9d, 0x99, 0xe3, 0xb8,
// 	0x8d, 0x25, 0x30, 0xfc, 0xc6, 0x2f, 0x8b, 0x73,
// 	0xe2, 0x18, 0xac, 0xae, 0x77, 0xca, 0x86, 0x2d,
// 	0x9e, 0x90, 0xbc, 0xce, 0x33, 0x26, 0xea, 0xf2,
// 	0xaf, 0xb4, 0x39, 0xac, 0x22, 0xd7, 0x52, 0x93,
// 	0x43, 0x45, 0xe2, 0x9c, 0xe5, 0x1b, 0x49, 0x15,
// 	0xa0, 0xce, 0xc6, 0xe3, 0x04, 0x28, 0x84, 0xc1,
// 	0x6d, 0x4d, 0x3e, 0x36, 0x80, 0x97, 0x3a, 0x7e,
// 	0xcc, 0x9c, 0xbc, 0xad, 0xda, 0x2e, 0x60, 0x08,
// 	0xaa, 0x0f, 0xc9, 0x29, 0xb4, 0xe7, 0xc8, 0xe6,
// 	0x0d, 0x96, 0x2c, 0xa0, 0x6b, 0xec, 0xa6, 0xc5,
// 	0x3f, 0xba, 0x13, 0x4c, 0xe4, 0xaf, 0xe9, 0xc0,
// 	0xf2, 0x61, 0xdf, 0x51, 0x46, 0xcd, 0x91, 0x55,
// 	0x56, 0x6b, 0x20, 0x71, 0x43, 0x05, 0xb1, 0xd2,
// 	0xb1, 0x4b, 0x91, 0xcd, 0x32, 0x24, 0x82, 0xbc,
// 	0x25, 0x0a, 0x51, 0x13, 0xbb, 0x67, 0x65, 0x79,
// 	0x5a, 0x3c, 0xee, 0x7a, 0x5a, 0xfb, 0x71, 0x5e,
// 	0x84, 0xd8, 0xbb, 0x58, 0xe3, 0xcb, 0x0d, 0x51,
// 	0x99, 0x96, 0xde, 0x1d, 0x1a, 0xf2, 0x23, 0x06,
// 	0x55, 0x26, 0x10, 0x3d, 0xef, 0xf9, 0xb6, 0x37,
// 	0xa3, 0x1d, 0x43, 0x5e, 0x02, 0x1c, 0x08, 0xfd,
// 	0x40, 0x58, 0xd5, 0xd5, 0x49, 0x7d, 0x2b, 0xd3,
// 	0x4d, 0xa5, 0xed, 0x69, 0x3f, 0xcc, 0x9b, 0xfb,
// 	0xd9, 0x4a, 0x5c, 0x69, 0xac, 0x4c, 0xe6, 0xa2,
// 	0x1b, 0x76, 0x8d, 0xbb, 0x9a, 0x25, 0xd9, 0x62,
// 	0xd4, 0x29, 0x5f, 0x74, 0xe8, 0x58, 0x6e, 0x38,
// 	0xf2, 0x15, 0xac, 0x7d, 0xb5, 0x75, 0x09, 0xd5,
// 	0x22, 0x88, 0x29, 0x39, 0xb3, 0xa3, 0x9c, 0x2c,
// 	0xf7, 0x2a, 0x7e, 0x63, 0x1d, 0x98, 0x28, 0xe3,
// };

// Example of RSA4096 OEM DSS key :
// uint8_t otp_header_slot = 2;                 // 0-based
// uint8_t otp_key_id = 2;                      // 0-based
// uint8_t otp_key_type = OTP_RSA_OEM_BE_PUBKEY;
// uint8_t otp_key_param = OTP_KPARAM_RSA4096;
// uint16_t otp_key_exp_len = 0b10001; // 65537
// uint32_t otp_key_offset = 0x840;              // otp data region offset for storing key
// uint32_t otp_key_len = 0x200;
// const uint8_t otp_pub_key[] = {
// 	0xAB, 0xEA, 0x1E, 0xB7, 0x57, 0xA5, 0x05, 0x3A,
// 	0xA7, 0xFA, 0xD3, 0x04, 0xC1, 0xDC, 0x5F, 0xE4,
// 	0x29, 0x56, 0xF7, 0xA1, 0xBC, 0xBB, 0xA8, 0xBB,
// 	0xFC, 0xFA, 0xB6, 0x7E, 0x53, 0xD4, 0x02, 0xF0,
// 	0xC7, 0xCE, 0xA4, 0x35, 0x96, 0x51, 0xF4, 0x74,
// 	0x8D, 0x8F, 0x1F, 0x50, 0xC0, 0xE4, 0x5D, 0x67,
// 	0xC7, 0x74, 0xB3, 0x1B, 0xE8, 0xE6, 0xE4, 0x61,
// 	0x33, 0xC4, 0x75, 0x44, 0x57, 0x51, 0x84, 0x0B,
// 	0x43, 0x68, 0x96, 0x42, 0x2A, 0x57, 0x56, 0xC5,
// 	0xD8, 0x06, 0x25, 0xF8, 0xB3, 0x32, 0xB5, 0x11,
// 	0x75, 0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x0F, 0x7A,
// 	0xC5, 0xB6, 0xA3, 0x69, 0x26, 0xA5, 0xA1, 0x4E,
// 	0x35, 0xFC, 0xF3, 0x82, 0xFD, 0x82, 0x04, 0xE7,
// 	0xC2, 0x29, 0x45, 0xE7, 0xEA, 0x54, 0xDA, 0x14,
// 	0x76, 0x27, 0x0B, 0x87, 0x31, 0x5C, 0x75, 0xE6,
// 	0x83, 0x4D, 0xDA, 0xBC, 0x63, 0xC4, 0x88, 0x50,
// 	0x56, 0xB8, 0x32, 0x50, 0x27, 0x0A, 0xCF, 0x82,
// 	0xCE, 0xAF, 0x04, 0xE6, 0x52, 0x61, 0x7B, 0x74,
// 	0xC5, 0x40, 0x95, 0x89, 0xDE, 0xC8, 0x37, 0xD2,
// 	0x76, 0x97, 0x0C, 0x8C, 0x3C, 0x2E, 0xAD, 0x78,
// 	0x70, 0xE6, 0xE7, 0x31, 0x00, 0xDA, 0xA0, 0x73,
// 	0x14, 0x52, 0xFC, 0xB4, 0xA3, 0x57, 0xC0, 0x41,
// };

// DO NOT change otp_retire_key_id for adding new key.
int32_t otp_retire_key_id = -1;  // valid range : 0 - 7
#endif
#endif
